nums = {
    'zero' : '0',
    'one' : '1',
    'two' : '2',
    'tree' : '3',
    'four' : '4',
    'five' : '5',
    'six' : '6',
    'seven' : '7',
    'eight' : '8',
    'nine' : '9'
    }


def prost(n):
    dels = 1
    for i in range(1, int(n / 2) + 1):
        if n % i == 0:
            dels += 1
    if dels == 2:
        return True
    return False


words = input().split()
num = ''
flag = True

if words[0] == 'zero':
    flag = False

for i in words:
    if i not in nums.keys():
        flag = False
if not flag:
    print('Wrong input')
else:
    for i in words:
        num += nums[i]
        
    num = int(num)
    nums = []
    flag = False

    for i in range(2147483647):
        if prost(num + i):
            nums.append(num + i)
            flag = True
        if prost(num - i):
            nums.append(num - i)
            flag = True
        if flag:
            break
    print(min(nums))
